package render;

import org.zkoss.zul.Label;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.ListitemRenderer;

import entities.LegLEGAJO;
import java.util.Calendar;

public class LegajosRenderer implements ListitemRenderer {

    public void render (Listitem listitem, Object value, int index) {
        LegLEGAJO leg = (LegLEGAJO)value;
        listitem.setValue(value);
        
        Calendar cal = Calendar.getInstance();
        cal.setTime(leg.getFechaNacimiento());
        
        String day = String.valueOf(cal.get(Calendar.DATE));
        if (Integer.parseInt(day)<10){
            day = '0'+day;
        }
        String month = String.valueOf(cal.get(Calendar.MONTH)+1);
        if (Integer.parseInt(month)<10){
            month = '0'+month;
        }
        String year = String.valueOf(cal.get(Calendar.YEAR));
        String birthdate = day+"/"+month+"/"+year;
        
        addListcell(listitem, leg.getLegajo());
        addListcell(listitem, leg.getApellido());
        addListcell(listitem, leg.getNombre());
        addListcell(listitem, leg.getTipoLegajo());
        addListcell(listitem, leg.getDocumentoNumero());
        addListcell(listitem, birthdate);
        addListcell(listitem, leg.getCuil());
        addListcell(listitem, leg.getCalle()+" "+leg.getNumero());
        addListcell(listitem, leg.getLocalidad());

    }
    private void addListcell (Listitem listitem, String value) {
        Listcell lc = new Listcell ();
        Label lb = new Label(value);
        lb.setParent(lc);
        lc.setParent(listitem);
    }

}
